//
//  YGKJActivityVC.m
//  新项目
//
//  Created by 刘耀宗 on 2016/10/21.
//  Copyright © 2016年 刘耀宗. All rights reserved.
//

#import "YGKJActivityVC.h"
#import "DQTestView.h"
#import "WBPopMenuModel.h"
#import "WBPopMenuSingleton.h"
#import "YGKJChooeNum.h"
@interface YGKJActivityVC ()<YGKJChooeNumDelegate>
@property (nonatomic, strong) DQTestView *testView;
@property (nonatomic, strong) YGKJChooeNum *numView;
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) NSArray *sourceArr;
@end

@implementation YGKJActivityVC
-(UIImageView *)imageView
{
    if (_imageView == nil) {
        _imageView = [[UIImageView alloc] init];
        _imageView.image=[UIImage imageNamed:@"彩票_02"];
    }
    return _imageView;

}
-(YGKJChooeNum *)numView
{
    if (_numView == nil) {
        _numView = [YGKJChooeNum ViewWithXib];
        _numView.delegate=self;
    }
    return _numView;

}
- (NSArray *) titles {
    return @[@"双色球",
             @"重庆时时彩",
             @"超级大乐透",
             @"PK10",
             @"PC蛋蛋",
             @"排列三",
             @"排列5",
             @"7乐彩",
             @"新快5"];
}
- (void)viewDidLoad {
    [super viewDidLoad];
   self.navigationItem.title = @"走势";
    self.view.backgroundColor=[UIColor whiteColor];
    
    UIBarButtonItem *rightItem=[[UIBarButtonItem alloc] initWithTitle:@"彩种" style:UIBarButtonItemStylePlain target:self action:@selector(clickForChoose)];
    self.navigationItem.rightBarButtonItem=rightItem;
    [self.view addSubview:self.numView];
    self.numView.frame=CGRectMake(0, 0, newwidth, 44);
    [self.view addSubview:self.imageView];
    self.imageView.frame=CGRectMake(15, 38, 30,8);
    
    DQTestView *testView = [[DQTestView alloc]initWithFrame:CGRectMake(0, 64, 375, 667)
                            ];
    self.testView=testView;
    [self.view addSubview:testView];
    self.sourceArr=@[@"56期",@"55期",@"54期",@"53期",@"52期",@"51期",@"50期",@"49期",@"48期",@"47期"];
}
-(void)btnClickWithTag:(NSInteger)tag
{
    [self showImageAminaWwithNum:tag];
    self.testView.yDatas=self.sourceArr;
    //                                                               weakSelf.testView.xDatas
    self.testView.xDatas=@[@"05",@"23",@"24",@"3",@"4",@"56",@"34",@"7",@"8",@"9"];
    [self.testView.fillDatas removeAllObjects];
    [self.testView.frameArr removeAllObjects];
    for (NSInteger i=0; i<self.testView.xDatas.count; i++) {
        NSString *number = [self randomFormArray:self.testView.xDatas];
        
        [self.testView.fillDatas addObject:number];
    }
    [self.testView setNeedsDisplay];
    NSLog(@"index:%ld",(long)index);

}
//动画
-(void)showImageAminaWwithNum:(NSInteger)num
{
    if (num==1) {
        [UIView animateWithDuration:0.25 animations:^{
                self.imageView.frame=CGRectMake(15, 38, 30,8);
        }];
    }else if (num==2)
    {
        [UIView animateWithDuration:0.25 animations:^{
                self.imageView.frame=CGRectMake((newwidth-30-5*30)/4+15+30, 38, 30,8);
        }];
    
    }else if (num==3)
    {
        [UIView animateWithDuration:0.25 animations:^{
                 self.imageView.frame=CGRectMake((newwidth-30-5*30)/4*2+15+30*2, 38, 30,8);
        }];
    }else if (num==4)
    {
        [UIView animateWithDuration:0.25 animations:^{
                   self.imageView.frame=CGRectMake((newwidth-30-5*30)/4*3+15+30*3, 38, 30,8);
        }];
    }else if (num==5)
    {
        [UIView animateWithDuration:0.25 animations:^{
               self.imageView.frame=CGRectMake((newwidth-30-5*30)/4*4+15+30*4, 38, 30,8);
        }];
    
    }
    


}
//选择彩种
-(void)clickForChoose
{ NSMutableArray *obj = [NSMutableArray array];
    
    for (NSInteger i = 0; i < [self titles].count; i++) {
        
        WBPopMenuModel * info = [WBPopMenuModel new];
//        info.image = [self images][i];
        info.title = [self titles][i];
        [obj addObject:info];
    }
    WEAKSELF
    [[WBPopMenuSingleton shareManager]showPopMenuSelecteWithFrame:120
                                                             item:obj
                                                           action:^(NSInteger index) {
                                                               weakSelf.testView.yDatas=@[@"056期",@"57期",@"58期",@"589期",@"05期",@"06期",@"07期",@"08期",@"09期",@"10期"];
//                                                               weakSelf.testView.xDatas
weakSelf.testView.xDatas=@[@"05",@"23",@"24",@"3",@"4",@"56",@"34",@"7",@"8",@"9"];
                                                               [weakSelf.testView.fillDatas removeAllObjects];
                                                               [weakSelf.testView.frameArr removeAllObjects];
                                                               for (NSInteger i=0; i<weakSelf.testView.xDatas.count; i++) {
                                                                   NSString *number = [self randomFormArray:weakSelf.testView.xDatas];
                                                                   
                                                                   [weakSelf.testView.fillDatas addObject:number];
                                                               }
                                                               [weakSelf.testView setNeedsDisplay];
                                                               NSLog(@"index:%ld",(long)index);
                                                               
                                                           }];


    
}
- (NSString *)randomFormArray:(NSArray *)array{
    
    NSInteger count = array.count;
    NSInteger index = arc4random()%count;
    
    return [NSString stringWithFormat:@"%ld",index];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
